import logging
import time

import task.task1 as task1
import task.task2 as task2
import task.task3 as task3
import task.task4 as task4


class Tf2_info:
    def __init__(self):
        self.list_watchSallite = None
        self.list_calculateSallite = None


tf2_info = Tf2_info()

some_flag2 = False

# 定义触发条件函数
def trigger_condition2():
    # sql = 'select * from satcontrol.simflag where id = 1'
    # cur.execute(sql)
    # conn.commit()
    # flag_set = cur.fetchall()
    # startflag = flag_set[0][2]
    # if startflag == 1:
    #     some_flag1 = True
    # # 模拟触发条件
    return some_flag2


# Task1 : 数据准备
def Scene2_task1():
    logging.info("====================================")
    logging.info("Scene-2 task1 执行任务 1 : 数据准备")
    logging.info("************************************")
    logging.info("Scene-2 task1 开始...")
    time.sleep(2)

    task1.run()
    tf2_info.list_watchSallite = task1.res()

    logging.info("Scene-2 task1 结束...")
    logging.info("------------------------------------")



# Task2 : 调度评估
def Scene2_task2():
    logging.info("====================================")
    logging.info("Scene-2 task2 执行任务 2 : 调度评估")
    logging.info("************************************")
    logging.info("Scene-2 task2 开始...")
    time.sleep(2)

    task2.run()
    tf2_info.list_calculateSallite = task2.res()

    logging.info("Scene-2 task2 结束...")
    logging.info("------------------------------------")



# Task3 : 数据传到主星 
def Scene2_task3():
    logging.info("====================================")
    logging.info("Scene-2 task3 执行任务 3 : 数据传到主星")
    logging.info("************************************")
    logging.info("Scene-2 task3 开始...")
    time.sleep(2)

    # 默认计算星列表的第一个是计算主星
    task3.set(tf2_info.list_watchSallite, tf2_info.list_calculateSallite)
    task3.run()

    logging.info("Scene-2 task3 结束...")
    logging.info("------------------------------------")

    
# Task4 : 主星协同计算 
def Scene2_task4():
    logging.info("====================================")
    logging.info("Scene-2 task4 执行任务 4 : 主星协同计算")
    logging.info("************************************")
    logging.info("Scene-2 task4 开始...")
    time.sleep(2)

    task4.run()

    logging.info("Scene-2 task4 结束...")
    logging.info("------------------------------------")

